<template>
  <base-breadcrumb :title="$route.meta.title">
    <!-- 技术服务支持编辑2 -->
    <a-form-model
      class="updateServiceSupport"
      ref="ruleForm"
      :model="form"
      :label-col="{ span: 6 }"
      :wrapper-col="{ span: 18 }"
      :rules="(editModel == 0 && !todoFlag) ? {} : rules"
      :class="editModel==0?'displayFrom':''"
    >
      <a-spin :spinning="loading">
        <!-- 表单 -->
        <a-card
          :bordered="false"
          class="basicInfo"
        >
          <title-name title="基本信息"></title-name>
          <custom-form
            :formList="formList"
            :form="form"
            :is-emit="false"
            :editModel="editModel == 0 ? '' : ''"
            class="updateServiceSupport-form"
            @selectOrg="selectOrg"
          >
            <!-- 附件上传 -->
            <template #fileInfoList>
              <template v-if="editModel != 0 && !demandPlanFlag">
                <l-table
                  businessCode="FACE14"
                  :uploadArrys.sync="form.fileInfoList"
                ></l-table>
              </template>
              <file-link
                v-else
                :fileList="form.fileInfoList"
                style="margin-top: -3px"
              ></file-link>
            </template>
            <template #imageFile>
              <div
                v-if="editModel == 0 && (!form.imageFile || form.imageFile.length < 1)"
                style="margin-top: -3px;"
              >
                无
              </div>
              <l-table
                v-else
                uploadType="image"
                businessCode="FACE14"
                :disabled="editModel == 0 || demandPlanFlag"
                :editModel="editModel"
                :uploadArrys.sync="form.imageFile"
                multiple
              ></l-table>
            </template>
          </custom-form>
        </a-card>
        <template v-if="!todoFlag">
          <a-card
            :bordered="false"
            v-if="demandProcessFlag"
          >
            <title-name title="需求处理"></title-name>
            <custom-form
              :formList="formListTwo"
              :form="form"
              :is-emit="false"
              :editModel="editModel == 0 ? '' : ''"
            >
            </custom-form>
          </a-card>
        </template>
        <a-card
          :bordered="false"
          v-if="!todoFlag && !detailDataExpertList"
        >
          <title-name title="专家指派"></title-name>
          <p>
            <span style="margin: 0 15px 0 30px">专家选择:</span>
            <a-button
              type="primary"
              @click="addExpert"
              v-if="editModel != 0"
            >添加专家</a-button>
          </p>
          <a-table
            :columns="columns"
            :data-source="form.expertListData"
            bordered
            style="margin: 0 30px"
          >
            <span
              slot="serial"
              slot-scope="text, record, index"
            >{{ index + 1 }}</span>
            <span
              slot="action"
              slot-scope="text, record, index"
            >
              <template>
                <a
                  @click="delExpert(index)"
                  v-if="(record.leaderCode * 1 === 0 || editModel===2) && editModel!=0"
                >删除</a>
              </template>
            </span>
          </a-table>
        </a-card>
        <a-card
          :bordered="false"
          v-if="todoFlag && isReturnReceipt || detailData.processResultInfo"
        >
          <title-name title="处理结果"></title-name>
          <custom-form
            :formList="formOpinion"
            :form="form"
            :is-emit="false"
            :editModel="''"
          >
            <!-- 附件上传 -->
            <template #processResultFile>
              <template v-if="todoFlag && isReturnReceipt">
                <l-table
                  :disabled="resolveInfo"
                  businessCode="FACE14"
                  :uploadArrys.sync="form.processResultFile"
                ></l-table>
              </template>
              <file-link
                v-else
                :fileList="form.processResultFile"
                style="margin-top: -3px"
              ></file-link>
            </template>
          </custom-form>
        </a-card>
        <a-card
          :bordered="false"
          v-if="todoFlag && !isReturnReceipt || detailDataExpertList"
        >
          <title-name title="专家服务评分"></title-name>
          <div
            class="serviceScore"
            v-for="(item, index) in form.expertListData"
            :key="index"
          >
            <!-- <a-form-model-item label="专家名称">
              <BaseInput v-model="item.expertName" />
            </a-form-model-item> -->

            <!-- <a-row>
          <a-col :span="12">
            <a-form-model-item label="专家名称">
              <BaseInput v-model="item.employeeName" disabled/>
            </a-form-model-item>
          </a-col>
           <a-col :span="12">
            <a-form-model-item label="服务评价"   :prop="'item.' + index + '.evaluationId'">
              <a-select v-model="item.evaluationId">
            <a-select-option v-for="item in scoreType" :key="item.value">{{ item.label }}</a-select-option>
        </a-select>
            </a-form-model-item>
          </a-col>
            <a-col :span="24">
            <a-form-model-item label="备注">
              <a-textarea v-model="item.remark"  placeholder="对本次专家服务的评价概述，限300字" :maxLength='300'/>
            </a-form-model-item>
          </a-col>
        </a-row> -->
            <custom-form
              :formList="serviceScore"
              is-validate
              :form="item"
              :rules="rulesTwo"
              :is-emit="false"
              :editModel="''"
            ></custom-form>
          </div>
        </a-card>
      </a-spin>
    </a-form-model>
     
    <!-- 页脚操作栏 -->
    <div
      class="btn_box page-btn-right-top"
      v-if="editModel != 0"
    >
      <a-button
        v-if="resolveInfo"
        @click="handleActiveClose"
      >
        关闭
      </a-button>
      <template v-else>
        <a-button
          class="button_right"
          v-if="form.status == 'REJECTED'"
          type="primary"
          :loading="loadingBtn.REJECTED"
          @click="handleSubmit('REJECTED')"
        >保存</a-button>
        <a-button
          v-else
          class="button_right"
          type="primary"
          :loading="loadingBtn.DRAFT"
          @click="handleSubmit('DRAFT', '0')"
        >保存草稿</a-button>
        <a-button
          class="button_right"
          type="primary"
          :loading="loadingBtn.SUBMITTED"
          @click="handleSubmit('SUBMITTED', '1')"
        >提交</a-button>
        <a-button @click="handleActiveClose">关闭</a-button>
      </template>
    </div>
    <div
      class="btn_box page-btn-right-top"
      v-else
    >
      <a-button
        v-if="todoFlag && !resolveInfo"
        class="button_right"
        type="primary"
        :loading="loadingBtn.SUBMITTED"
        @click="handleSubmit('SUBMITTED')"
      >提交</a-button>
      <a-button @click="handleActiveClose">关闭</a-button>
    </div>
    <a-modal
      width="500px"
      :visible.sync="visible.visibleExpert"
      :title="'选择专家'"
      @cancel="visible.visibleExpert = false"
      @ok="changeExpert"
    >
      <a-form-model
        :model="expertForm"
        :rules="rulesExpert"
        ref="ruleFormListExpert"
      >
        <div class="changeExpert">
          <custom-form
            :formList="formListExpert"
            :form="expertForm"
            :is-emit="false"
            :editModel="editModel == 0 ? '' : ''"
          ></custom-form>
        </div>
      </a-form-model>
    </a-modal>
  </base-breadcrumb>
</template>

<script>
import { addSupport, getSupportDetail, technicalPullInfo } from '@/api/technical/serviceSupport'
import { finishBusinessTodo } from '@/api/commons.js'
import { getExpertList, getExpertGroup } from '@/api/science'
import { getExpertLsit } from '@/api/technical/expert'
import { getTechnicalServiceNeedsByIdDetail } from '@/api/technical/serviceDemand'
import BaseEditPage from '@/views/baseEditPage' // 编辑详情页基础配置
import BSelect from '@/components/BComponents/BSelect'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from './supportSelectProject'
import ASelectOrgPeople from '@/components/Select/ASelectOrgPeople' //联系人项目加岗位
import { technicalServiceType, demandPlan, scoreType } from './model'
import { isPhone, createValidator } from '@/utils/regExpression.js'
import DialogForm from '@/components/DialogForm' // 弹窗
import { getAllBranchCompany } from '@/api/commons'
import { getAuditProject } from '@/api/themeChoose/themeChoose'
const columns = [
  { title: '序号', dataIndex: 'serial', width: 65, scopedSlots: { customRender: 'serial' } },
  { title: '专家委员会', dataIndex: 'expertGroupName', width: '180px', ellipsis: true },
  { title: '姓名', dataIndex: 'expertName', width: '180px', ellipsis: true },
  { title: '所属组织机构', dataIndex: 'supportOrgName', width: '180px', ellipsis: true },
  { title: '所属项目', dataIndex: 'projectName', width: '180px', ellipsis: true },
  { title: '职务', dataIndex: 'jobTitle', width: '180px', ellipsis: true },
  { title: '职称', dataIndex: 'jobName', width: '180px', ellipsis: true },
  { title: '联系电话', dataIndex: 'phoneNum', width: '180px', ellipsis: true },
  { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' }, width: '120px', ellipsis: true }
]
export default {
  name: 'a' + Date.now(),
  extends: new BaseEditPage(),
  components: {
    SelectProject,
    BSelect,
    SelectSubCompany,
    ASelectOrgPeople,
    DialogForm
  },
  data() {
    this.columns = columns
    return {
      loading: false, // 加载控件
      visible: false, //人员选择控件
      editModel: 0, // 操作状态:0 查看;1 编辑;2 新增
      demandPlanFlag: false, //是否为需求内
      demandProcessFlag: true, //是否需求处理
      expertGroupList: [], // 专家组列表
      addExpertData: {},
      expertList: [], //专家列表
      detailDataExpertList: false,
      todoFlag: false,
      getNameListData: [],
      switchInfo: 205,
      isReturnReceipt: null, //是否为回执
      scoreType: scoreType,
      detailData: {},
      queryParam: {
        //专家列表传参
        pageNo: 1,
        pageSize: 100000,
        query: {
          expertTypeId: null
        }
        //expertGroupId: null
      },
      visible: {
        visibleExpert: false
      },
      expertListFlag: true,
      expertForm: {},
      querCompany: [],
      projectData: [],
      form: {
        supportOrgName: '',
        projectName: '',
        projectId: '',
        monitoringTime: [],
        expertListData: [],
        curId: '',
        supportOrgId: ""
      }, // 表单
      clearForm: {},
      // serviceScoreData: [
      //   { name: 1, score: 1, remark: '专家技术非常好' },
      //   { name: 1, score: 1, remark: '专家技术非常好' }
      // ],
      id: '',
      loadingBtn: {
        DELETE: false,
        DRAFT: false,
        SUBMITTED: false,
        REJECTED: false,
        changeExpert: false
      },
      expertData: [],
      rules: {
        supportOrgId: [{ required: true, message: '请选择所属组织机构', trigger: 'change' }],
        curId: [{ required: true, message: '请选择', trigger: 'change' }],
        supportPlanId: [{ required: true, message: '请选择需求计划', trigger: 'change' }],
        technicalServerName: [
          { required: true, message: '请输入技术服务名称', trigger: 'blur' },
          { min: 1, max: 20, message: '长度不得超过20字', trigger: 'blur' }
        ],
        technicalServerId: [{ required: true, message: '请选择技术服务名称', trigger: 'change' }],
        placeName: [{ required: true, message: '请输入地点', trigger: 'blur' }],
        remark: [{ required: true, message: '请输入备注', trigger: 'blur' }],
        fileInfoList: [{ type: 'array', required: true, message: '请上传附件', trigger: 'blur' }],
        overallSituation: [{ required: true, message: '请输入整体概况', trigger: 'blur' }],
        technicalServerContent: [{ required: true, message: '请输入技术服务需求内容', trigger: 'blur' }],
        contactPersonId: [{ required: true, message: '请选择联系人', trigger: 'change' }],
        monitoringTime: [{ required: true, message: '请选择时间', trigger: 'change' }],
        contactPhoneNum: [
          { required: true, message: '请输入联系人手机', trigger: 'blur' },
          { validator: createValidator(isPhone, '请输入正确的手机号'), trigger: 'blur' }
        ],
        meetingOnOrOff: [{ required: true, message: '请选择是否召开会议', trigger: 'change' }],
        meetingPlace: [{ required: true, message: '请输入会议地点', trigger: 'blur' }],
        meetingTime: [{ required: true, message: '请选择会议时间', trigger: 'change' }],
        meetingHost: [{ required: true, message: '请输入主持人/主讲人', trigger: 'blur' }],
        allInfo: [{ required: true, message: '请输入整体概况', trigger: 'blur' }],
        processResultInfo: [{ required: true, message: '请输入处理意见', trigger: 'blur' }]
      }, // 校验规则
      rulesExpert: {
        expertGroup: [{ required: true, message: '请选择', trigger: 'change' }],
        selectExpert: [{ required: true, message: '请选择', trigger: 'change' }]
      },
      rulesTwo: {
        evaluationId: [{ required: true, message: '请选择服务评价', trigger: 'change' }]
      },
      init: false // 初始化控件
    }
  },
  watch: {
    // 监听附件实现附件校验
    'form.fileInfoList'() {
      if (this.editModel != 0 && this.init) {
        this.$nextTick(() => {
          this.$refs.ruleForm?.validateField('fileInfoList')
        })
      }
    },
    // 监听照片实现照片校验
    'form.imageFile'() {
      if (this.editModel != 0 && this.init) {
        this.$nextTick(() => {
          this.$refs.ruleForm?.validateField('imageFile')
        })
      }
    },
    'form.projectId'(val) {
      this.form.technicalServerTypeId = val ? '1' : '0' //有项目就是项目技术服务，反之业务管控服务
    },
    'form.supportOrgId'(val) {
      let supportOrgName = ''
      if (val) {
        supportOrgName = this.querCompany.find((item) => item.id === val).name
        this.$set(this.form, 'supportOrgName', supportOrgName)
        this.form.supportOrgName = supportOrgName
      }
    },
    'expertForm.expertGroup'(val) {
      if (val) {
        this.expertForm = {
          expertGroup: val
        }
      }
    },
    'visible.visibleExpert'(val) {
      !val && setTimeout(this.$refs.ruleFormListExpert.clearValidate())
    }
  },
  computed: {
    // 是否是业务待办查看处理信息
    resolveInfo: {
      get() {
        return this.$route.query?.resolveInfo === 'true'
      },
      set() {}
    },
    formList() {
      return [
        {
          label: '所属单位',
          type: 'orgTree',
          keyName: 'curId',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
          span: 16,
          isAutoSelectFirst:false,
          isNeedAuth:true,
          checkStrictly: false,
          disabled: this.editModel == 0,
          needTags: ['CO', "BC", "PD"],
          isQueryProjecDetail: false
        },
        // {
        //   type: 'a-select',
        //   keyName: 'supportOrgId',
        //   label: '所属组织机构',
        //   data: this.querCompany,
        //   placeholder: '请选择所属组织机构',
        //   disabled: this.editModel == 0,
        //   replaceFields: {
        //     label: 'name',
        //     value: 'id'
        //   },
        //   change: (e) => {
        //     console.log(e)
        //   }
        // },
        // {
        //   type: SelectProject,
        //   keyName: 'projectId',
        //   viewName: 'projectName',
        //   disabled: this.editModel == 0,
        //   placeholder: '请选择所属项目',
        //   label: '所属项目',
        //   attrs: {
        //     autoSelected: this.editModel == 2,
        //     keyValue: 'supportOrgId',
        //     isClear: this.editModel == 2,
        //     isEdit: this.editModel != 2,
        //     //isSelf:false,
        //     form: this.form
        //   },
        //   selectChange: (e) => {
        //     this.$set(this.form, 'projectDeptId', e?.projectDeptId)
        //   }
        // },
        {
          keyName: 'supportPlanId',
          type: 'a-select',
          disabled: this.editModel == 0,
          label: '需求计划',
          data: demandPlan,
          change: (e) => {
            if(e*1==0){
             this.$set(this.rules.fileInfoList[0], 'required', false)
            }else{
              this.$set(this.rules.fileInfoList[0], 'required', true)
            }
            this.changeDemandPlan(e)
          }
        },
        {
          keyName: 'technicalServerId',
          type: 'a-select',
          disabled: this.editModel == 0,
          hidden: !this.demandPlanFlag,
          label: '技术服务名称',
          data: this.getNameListData,
          replaceFields: {
            label: 'name',
            value: 'id'
          },
          attrs: {
            form: this.form
            //request: this.getNameList
          },
          change: (e) => {
            //切换名称获取数据
            this.getTechnicalServiceNeedsByIdDetailFn(e)
            // this.form.monitoringTime = [`${e.needStartTime} 00:00`, `${e.needStartTime} 00:00`]
            // this.form.placeName = e.place
            // this.form.technicalServerTypeId = e.type.toString()
            // this.form.designChangeName = e.name
            // this.form.contactPersonId = e.linkmanId
            // this.form.allInfo = e.overallSituation
            // this.form.technicalServerContent = e.content
            // this.form.imageFile = e.photo
            // this.form.remark = e.remark
            // this.form.fileInfoList = e.fileInfoList
          }
        },
        {
          keyName: 'technicalServerName',
          type: 'BaseInput',
          disabled: this.editModel == 0,
          label: '技术服务名称',
          hidden: this.demandPlanFlag
        },
        {
          keyName: 'monitoringTime',
          type: 'a-range-picker',
          placeholder: ['请选择日期', '请选择日期'],
          disabled: this.demandPlanFlag || this.editModel == 0,
          label: '时间',
          span: 8,
          attrs: {
            valueFormat: 'YYYY-MM-DD HH:mm:ss',
            showTime: { format: 'YYYY-MM-DD HH:mm:ss' }
          }
        },
        {
          keyName: 'placeName',
          type: 'BaseInput',
          disabled: this.demandPlanFlag || this.editModel == 0,
          label: '地点'
        },
        {
          keyName: 'technicalServerTypeId',
          type: 'a-select',
          disabled: true,
          label: '技术服务类型',
          data: technicalServiceType
        },
        {
          keyName: 'contactPersonId',
          viewName: 'mainPeopleName',
          type: ASelectOrgPeople,
          disabled: this.demandPlanFlag || this.editModel == 0,
          label: '联系人',
          attrs: {
            init: false,
            keyValue: this.form.projectId ? 'projectDeptId' : 'supportOrgId'
          },
          onSelectChange: (e) => {
            this.$set(this.form, 'contactPersonName', e.name)
          }
        },
        {
          keyName: 'contactPhoneNum',
          type: 'BaseInput',
          disabled: this.demandPlanFlag || this.editModel == 0,
          label: '联系人手机'
        },
        {
          keyName: 'allInfo',
          type: 'BaseTextarea',
          disabled: this.demandPlanFlag || this.editModel == 0,
          label: '整体概况',
          span: 24
        },
        {
          keyName: 'technicalServerContent',
          type: 'BaseTextarea',
          disabled: this.demandPlanFlag || this.editModel == 0,
          label: '技术服务需求内容',
          span: 24
        },
        {
          slot: true,
          keyName: 'imageFile',
          label: ' ',
          span: 24,
          disabled: this.demandPlanFlag || this.editModel == 0,
          businessCode: 'FACE14'
        },
        {
          keyName: 'remark',
          type: 'BaseTextarea',
          disabled: this.demandPlanFlag || this.editModel == 0,
          label: '备注',
          placeholder: '如果特殊情况或需求,请备注描述。',
          span: 24
        },
        {
          slot: true,
          keyName: 'fileInfoList',
          label: '附件上传',
          span: 24,
          businessCode: 'FACE14'
        }
      ]
    },
    formListTwo() {
      return [
        {
          keyName: 'meetingOnOrOff',
          type: 'a-radio-group',
          disabled: this.editModel == 0,
          label: '是否召开会议',
          data: [
            { label: '是', value: true },
            { label: '否', value: false }
          ]
        },
        {
          keyName: 'meetingHost',
          type: 'BaseInput',
          hidden: !this.form.meetingOnOrOff,
          disabled: this.editModel == 0,
          label: '主持人/主讲人'
        },
        {
          keyName: 'meetingPlace',
          type: 'BaseInput',
          hidden: !this.form.meetingOnOrOff,
          disabled: this.editModel == 0,
          label: '会议地点'
        },
        {
          keyName: 'meetingTime',
          type: 'a-date-picker',
          placeholder: '请选择日期',
          hidden: !this.form.meetingOnOrOff,
          disabled: this.editModel == 0,
          label: '会议时间',
          attrs: {
            valueFormat: 'YYYY-MM-DD HH:mm',
            showTime: { format: 'YYYY-MM-DD HH:mm' }
          }
        }
      ]
    },
    formListExpert() {
      return [
        {
          type: 'a-select',
          keyName: 'expertGroup',
          label: '专家委员会',
          span: 24,
          data: this.expertGroupList,
          placeholder: '请选择专家委员会',
          change: (e) => {
            this.queryParam.query.expertTypeId = e
            this.getPlansList(this.queryParam)
          }
        },
        {
          type: 'a-select',
          keyName: 'selectExpert',
          label: '选择专家',
          placeholder: '请选择专家',
          // disabled:this.expertListFlag,
          span: 24,
          data: this.expertList,
          change: (e) => {
            this.expertForm.selectExpert = e
          }
          //   attrs: :{
          //     mode: 'multiple',
          //  }
        }
      ]
    },
    formOpinion() {
      return [
        {
          keyName: 'processResultInfo',
          type: 'BaseTextarea',
          disabled: !this.todoFlag || !this.isReturnReceipt || this.resolveInfo,
          label: '处理意见',
          placeholder: '限1000字',
          span: 24,
          autoSize: { minRows: 10, maxRows: 10 },
          attrs: {
            maxLength: 1000
          }
        },
        {
          slot: true,
          keyName: 'processResultFile',
          label: '附件上传',
          span: 24,
          disabled: !this.todoFlag || !this.isReturnReceipt,
          businessCode: 'FACE14'
        }
      ]
    },
    serviceScore() {
      return [
        {
          keyName: 'expertName',
          type: 'BaseInput',
          disabled: true,
          label: '专家姓名'
        },
        {
          keyName: 'evaluationId',
          type: 'a-select',
          disabled: !this.todoFlag || this.resolveInfo,
          label: '服务评价',
          data: scoreType
        },
        {
          keyName: 'remark',
          type: 'BaseTextarea',
          disabled: !this.todoFlag || this.resolveInfo,
          label: '备注',
          placeholder: '如果特殊情况或需求,请备注描述。',
          span: 24
        }
      ]
    }
  },
  methods: {
    selectOrg(val) {
      if(val.length === 1 || val.length === 2) {
        this.form.supportOrgId = val[val.length - 1].orgId
      } else if(val.length > 2) {
        this.form.supportOrgId = val[val.length - 2].orgId
        this.form.projectId = val[val.length - 1].projectId
      }
      this.$refs.ruleForm.clearValidate('curId')
    },
    querCompanyFn() {
      return getAllBranchCompany({ tagCodes: ['BC'] }).then((res) => {
        let co = [
          {
            id: '53085e2c9f1f4685801ef31994f57c49',
            name: '总部机关'
          }
        ]
        res.data = [...co, ...res.data]
        this.querCompany = res.data
      })
    },
    async getNameList() {
      return technicalPullInfo().then((res) => {
        this.getNameListData = res.data
        // return { code: 200, data: res.data }
      })
    },
    async getProject(e) {
      let args = { deptOrgIds: [this.$currentPost().id] }
      this.projectData = []
      if (e) {
        let data = await getAuditProject(args)
        this.projectData = data.data
        if (this.projectData.length > 0) {
          this.form.projectId = this.projectData[0].projectId
        }
        this.form.technicalServerTypeId = this.form.projectId ? '1' : '0'
      }
    },
    getTechnicalServiceNeedsByIdDetailFn(e) {
      this.loading = true
      getTechnicalServiceNeedsByIdDetail({ id: e })
        .then((res) => {
          this.loading = false
          this.form.monitoringTime = [`${res.data.needStartTime} 00:00`, `${res.data.needStartTime} 00:00`]
          this.form.placeName = res.data.place
          this.form.technicalServerTypeId = res.data.type.toString()
          this.form.technicalServerName = res.data.name
          this.form.contactPersonId = res.data.linkmanId
          this.form.allInfo = res.data.overallSituation
          this.form.technicalServerContent = res.data.content
          this.form.imageFile = res.data.photo
          this.form.remark = res.data.remark
          this.form.fileInfoList = res.data.fileInfoList
          this.form.imageFile = res.data.photo
          this.form.contactPhoneNum = res.data.phone
          // if(res.data.needStartTime && res.data.needEndTime){
          //   res.data.monitoringTime = [res.data.needStartTime,res.data.needEndTime]
          // }
          // res.data.type = res.data.type.toString()
          // this.form = { ...this.form, ...res.data }
          this.$nextTick(() => {
            this.init = true
          })
        })
        .catch(() => {
          this.loading = false
        })
    },
    async getExpertGroupList() {
      this.expertGroupList = []
      let { data } = await getExpertGroup()
      if (data.length) {
        data.map((item) => {
          if (item.status * 1 === 1) {
            this.expertGroupList.push({
              value: item.expertGroupId,
              label: item.expertGroupName
            })
          }
        })
      }
    },
    // 获取专家数据
    async getPlansList(str) {
      this.expertListFlag = true
      this.formListExpert[1].placeholder = '专家数据请求中'
      let res = await getExpertLsit(str)
      this.expertListFlag = false
      this.formListExpert[1].placeholder = '请选择专家'
      var findData = {}
      if (this.queryParam.query.expertTypeId && this.expertGroupList.length > 0) {
        findData = this.expertGroupList.find((item) => item.value === this.queryParam.query.expertTypeId)
      }
      this.expertList = []
      if (res.code == 200) {
        if (res.data.length > 0) {
          res.data.map((item) => {
            ;(item.value = item.expertId),
              (item.label = item.expertName),
              (item.expertGroupId = findData.value), //将专家委员会数据代入
              (item.expertGroupName = findData.label)
          })
          this.expertList = res.data
        }
      }
    },
    //切换时清空数据
    changeDemandPlan(val) {
      this.clearForm = this.$clone(this.form)
      this.$refs.ruleForm.clearValidate()
      this.demandPlanFlag = val * 1 === 0 ? true : false
      this.demandProcessFlag = this.demandPlanFlag
      this.form = {
        supportOrgId: this.clearForm.supportOrgId,
        projectId: this.clearForm.projectId,
        monitoringTime: [],
        supportPlanId: this.clearForm.supportPlanId,
        technicalServerTypeId: this.clearForm.technicalServerTypeId,
        expertListData: this.clearForm.expertListData,
        supportOrgName: this.clearForm.supportOrgName,
        projectDeptId: this.clearForm.projectDeptId
      }
    },
    //添加专家
    addExpert() {
      this.visible.visibleExpert = true
    },
    //删除专家
    delExpert(index) {
      this.form.expertListData.splice(index, 1)
    },
    //保存专家
    changeExpert() {
      this.$refs.ruleFormListExpert.validate((valid) => {
        if (valid) {
          this.visible.visibleExpert = false
          this.addExpertData = this.expertList?.find((item) => item.expertId === this.expertForm.selectExpert)
          if (this.form.expertListData.length > 0) {
            const cloneExpertListData = JSON.parse(JSON.stringify(this.form.expertListData))
            cloneExpertListData.filter((v) => v.expertId === this.addExpertData.expertId).length || this.form.expertListData.push(this.addExpertData)
          } else {
            this.form.expertListData = [this.addExpertData]
          }
          if (this.form.expertListData.length > 0) {
            this.form.expertListData.map((item, index) => {
              if (index == 0) {
                item.leaderCode = 1
              } else {
                item.leaderCode = 0
              }
            })
          }
        } else {
          this.$message.warning("请填写完所有必填项信息")
        }
      })
    },
    validateForm() {
      let flag = false
      this.$refs.ruleForm.validate((e) => {
        if (e) {
          flag = true
        }else {
          this.$message.warning('请填写完所有必填项信息')
        }
      })
      return flag
    },
    getDetailData() {
      // 不为添加时请求详情
      if (this.editModel != 2) {
        this.loading = true
        getSupportDetail({ id: this.id })
          .then((res) => {
            this.loading = false
            if (res.data.beginTime && res.data.endTime) {
              res.data.monitoringTime = [res.data.beginTime, res.data.endTime]
            }
            this.form = { ...this.form, ...res.data }
            if(this.form.projectId) {
              this.form.curId = this.form.projectId
            } else {
              this.form.curId = this.form.supportOrgId
            }
            this.demandProcessFlag = this.form.supportPlanId * 1 === 0 ? true : false
            this.demandPlanFlag = this.demandProcessFlag
            this.getNameListData.push({
              //因为查看技术服务名称数据被去除。所以导致回显有问题
              name: res.data.technicalServerName,
              id: res.data.technicalServerId
            })
            this.form.expertListData = []
            if (this.form.expertList.length > 0) {
              res.data.expertList.map((item) => {
                this.form.expertListData.push({
                  expertName: item.expertName,
                  expertGroupName: item.expertsUnionName,
                  expertId: item.expertId,
                  leaderCode: item.leaderCode,
                  remark: item.remark,
                  title: item.jobName,
                  phoneNum: item.phoneNum,
                  projectName: item.projectName,
                  evaluationId: item.evaluationId,
                  supportOrgName: item.orgName,
                  jobTitle: item.jobTitle,
                  jobName: item.jobName
                })
              })
            }
            this.detailData = res.data
            this.detailDataExpertList = res.data.expertList && res.data.expertList[0].evaluationId ? true : false //数组存在，且第一项评价数据存在
            this.$nextTick(() => {
              this.init = true
            })
          })
          .catch(() => {
            this.loading = false
          })
      } else {
        this.$nextTick(() => {
          this.init = true
        })
      }
    },
    /**
     * 提交表单
     */
    async handleSubmit(status, statusNum) {
      if (status == 'SUBMITTED' && !this.validateForm()) {
        return
      } else if (!this.form.expertListData.length > 0 && status != 'DRAFT') {
        this.$message.error('请添加专家')
        return
      } else if (this.noticeType * 1 === 206) {
        let everyEvaluationId = this.form.expertListData.every((item) => {
          return item.evaluationId
        })
        if (!everyEvaluationId) {
          this.$message.error('请选择服务评价')
          return
        }
      }
      this.loading = true
      this.loadingBtn[status] = true
      let form = this.$clone(this.form)
      if (form.monitoringTime?.length) {
        form.beginTime = form.monitoringTime[0]
        form.endTime = form.monitoringTime[1]
      }
      form.technicalServerType = form.technicalServerTypeId * 1 === 0 ? '业务管控服务' : '项目技术服务'
      form.expertList = []
      if (this.noticeType * 1 === 206) {
        form.status = 3
      } else {
        if (statusNum) {
          form.status = statusNum
        }
      }
      form.switchInfo = this.switchInfo
      // if(status != 'DRAFT'){
      //     form.switchInfo =this.switchInfo;
      // }
      console.log(form.expertListData)
      if (form.expertListData) {
        form.expertListData.map((item) => {
          form.expertList.push({
            expertName: item.expertName,
            expertsUnionName: item.expertGroupName,
            orgName: item.supportOrgName,
            expertId: item.expertId,
            leaderCode: item.leaderCode,
            remark: item.remark,
            jobName: item.jobName,
            phoneNum: item.phoneNum,
            projectName: item.projectName,
            evaluationId: item.evaluationId,
            jobTitle: item.jobTitle
          })
        })
      }
      delete form.expertListData
      delete form.monitoringTime
      let api = addSupport
      api(form)
        .then((res) => {
          this.loading = false
          this.loadingBtn[status] = false
          this.$message.success(status == 'SUBMITTED' ? '提交成功！' : '保存成功')
          if (res.status == 200 && this.noticeType) {
            // this.noticeType 存在就是在待办
            //成功关闭待办
            finishBusinessTodo({
              id: this.$route.query.messageId
            })
            // this.$noticeSuccess('操作成功')
            this.$close()
          }
          this.$multiTab.close()
        })
        .catch(() => {
          this.loadingBtn[status] = false
          this.loading = false
          this.$message.warning(err.data.message)
        })
    }
  },
  async mounted() {
    this.getNameList()
    this.querCompanyFn()
    this.todoFlag = this.type ? true : false //待办
    if (this.noticeType * 1 === 205) {
      this.isReturnReceipt = true
      this.switchInfo = 206
    } else if (this.noticeType * 1 === 206) {
      this.isReturnReceipt = false
      this.switchInfo = 0
    } else {
      this.switchInfo = 205
    }
    await this.getExpertGroupList()
    if (this.editModel * 1 === 2) {
      // let curOrg = this.ownOrgList.find((v) => {
      //   return v.id == this.curTagCode
      // })
      // this.form.supportOrgId = curOrg?.id
    } else {
      await this.getDetailData()
    }
    if (this.todoFlag) {
      this.$route.meta.title = '待办事项列表'
    } else {
      this.$route.meta.title = ['技术服务会议 查看', '技术服务会议 编辑', '技术服务会议 新增'][this.editModel]
    }
  }
}
</script>
<style lang="less" scoped>
@deep: ~'>>>';
.serviceScore {
  border-bottom: 1px solid #f5f5f5;
  margin-top: 10px;
  &:first-child {
    margin-top: 0;
  }
}
.updateServiceSupport {
  @{deep} .updateServiceSupport-form div:nth-last-child(3) .ant-col-6 label::after {
    content: '';
  }
  @{deep} .updateServiceSupport-form div:nth-child(5) .ant-form-item-children {
    display: block;
  }
  @{deep} .updateServiceSupport-form div:nth-child(5) .ant-calendar-picker {
    width: 100% !important;
  }
  @{deep} .ant-calendar-picker {
    width: 100% !important;
  }
}
</style>
